package postproblem

import (
	"html/template"
	"myOJ/datastructure"
	"net/http"
	"strings"
)

func PostProblemPage(w http.ResponseWriter, r *http.Request) {
	t := template.Must(template.ParseFiles("view/postproblem/postProblem.html"))
	t.Execute(w, nil)
}

func Posting(w http.ResponseWriter, r *http.Request) {
	cook := r.Header.Get("Cookie")
	poster := strings.Split(cook, "=")[0]

	ptitle := r.FormValue("ptitle")
	pdescription := r.FormValue("pdescription")
	args := r.FormValue("args")
	answerCode := r.FormValue("answerCode")

	problemPost := datastructure.ProblemPost{poster, ptitle, pdescription, args, answerCode}
	rowPostProblemProcess(problemPost)

	t := template.Must(template.ParseFiles("view/postproblem/posting.html"))
	t.Execute(w, nil)
}
